package com.aiti.lulian.pay;



import com.aiti.lulian.pay.model.AliPayPreOrderData;
import com.aiti.lulian.pay.model.PayInfo;
import com.aiti.lulian.pay.strategy.PayStrategy;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

public class PayStrategyContext {

    private final PayStrategy payStrategy;

    public PayStrategyContext(PayStrategy payStrategy) {
        this.payStrategy = payStrategy;
    }

    /**
     * 生成支付相关的信息
     * @param payInfo
     * @return
     */
    public AliPayPreOrderData genQrCode(PayInfo payInfo){
        return payStrategy.genPayQrCode(payInfo);
    }

    public String queryOrderStatus(String orderId) throws Exception {
        return payStrategy.queryOrderState(orderId);
    }

    /**
     * 获取支付前的token
     * @param userId
     * @return
     */
    public String genToken(String userId){
        return payStrategy.genToken(userId);
    }

    /**
     * 阿里支付成功能回调
     * @param params
     * @return
     */
    public String aliCallBack(Map<String, String> params) {
        return payStrategy.aliCallBack(params);
    }


    public String callBack(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return payStrategy.callBack(request, response);
    }
}
